<?php
defined('IN_IA') or exit('Access Denied');
global $_GPC, $_W;
$uniacid = $_W['uniacid'];
load()->func('tpl');
$pindex = max(1, intval($_GPC['page']));
$psize = 10;
$condition = "";
$condition2 = "";
$condition3 = "";
$condition4 = "";
if (!empty($_GPC['keyword'])) {
	$condition .= " AND CONCAT(`nickname`,`openid`,`uid`) LIKE '%{$_GPC['keyword']}%'";
}
if (!empty($_GPC['id'])) {
	$condition2 .= " AND CONCAT(`id`) = '{$_GPC['id']}'";
}
if (!empty($_GPC['status'])) {
	$condition3 .= " AND CONCAT(`status`) = '{$_GPC['status']}'";
}
if (!empty($_GPC['helpid'])) {
	$condition4 .= " AND CONCAT(`helpid`) = '{$_GPC['helpid']}'";
}
if (!empty($_GPC['uid'])) {
	$condition5 .= " AND CONCAT(`uid`) = '{$_GPC['uid']}'";
}
$set = pdo_fetch('SELECT * FROM ' . tablename($this->tableset) . ' WHERE uniacid = :uniacid', array(':uniacid' => $uniacid));
$list = pdo_fetchall("SELECT * FROM " . tablename($this->tableuser) . " WHERE uniacid = '{$_W['uniacid']} ' $condition $condition2 $condition3 $condition4 $condition5 ORDER BY displayorder DESC, id DESC LIMIT " . ($pindex - 1) * $psize . ",{$psize}");
if (!empty($list)) {
	foreach ($list as $item => $xfgw) {
		if (!empty($list[$item]['openid'])) {
			load()->model('mc');
			$list[$item]['fansinfo'] = mc_fansinfo($xfgw['openid']);
			$list[$item]['fanid'] = $list[$item]['fansinfo']['fanid'];
			$list[$item]['follow'] = $list[$item]['fansinfo']['follow'];
		}
		$list[$item]['vnum'] = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename($this->tablefav) . " WHERE uniacid = '{$_W['uniacid']}' AND openid = '{$list[$item]['openid']}'");
		$list[$item]['ynum'] = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename($this->tableuser) . " WHERE uniacid = '{$_W['uniacid']}' AND helpid = '{$list[$item]['uid']}'");
	}
	$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename($this->tableuser) . " WHERE uniacid = '{$_W['uniacid']}'  $condition $condition2 $condition3 $condition4 $condition5");
	$pager = pagination($total, $pindex, $psize);
}
include $this->template('listuser');